﻿using System;
using StartupTaskRunner.Configuration;
using StartupTaskRunner.Logging;

namespace StartupTaskRunner.Actions
{
    public class UnZipAction : ActionBase
    {
        public override string Type
        {
            get
            {
                return "UnZipType";
            }
        }

        public override void Execute()
        {
            IStorageDAL storageDal = StorageDALFactory.GetStorageDAL();

            string container = this.ContainerName;
            string archiveName = this.ArchiveName;
            string destinationFolder = this.DestinationLocation;

            // Determine blob container
            if (string.IsNullOrWhiteSpace(container))
            {
                container = ConfigType.GetBlobStorage().defaultContainer;
            }

            if (string.IsNullOrWhiteSpace(destinationFolder))
            {
                destinationFolder = Environment.CurrentDirectory;
            }

            Logger.WriteMessage("Copy resource from blob storage");
            Logger.WriteMessage("\tDestination folder: {0}", destinationFolder);
            Logger.WriteMessage("\tDownload from container: {0}", container);
            Logger.WriteMessage("\tDownloading resource: {0}", archiveName);
            Logger.WriteMessage("\tApply overwrite: {0}", Overwrite.ToString());
            storageDal.UnZipFromBlobStorage(container, archiveName, destinationFolder, Overwrite);
        }

        public bool Overwrite
        {
            get;
            set;
        }

        public string DestinationLocation
        {
            get;
            set;
        }

        public string ArchiveName
        {
            get;
            set;
        }

        public string ContainerName
        {
            get;
            set;
        }
    }
}
